home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / MIDI_MAN / CMIDIINP.C < prev    next >
Text File  |  1992-03-07  |  3KB  |  92 lines

  1. //--- CMIDIInputPort.c -----------------------------------------------------------------
  2. // Copyright ⌐ Paul Ferguson, 1990, 1991, 1992.  All rights reserved.
  3. //
  4. //    Superclass:     CDataPort
  5. //    Subclasses:     None
  6. //
  7. // Description:
  8. //    CMIDIInputPort.c defines a MIDI Manager port object.
  9. //
  10. //    For use with THINK C 5.0, the accompanying THINK Class Library (TCL), and MIDI
  11. //    Manager 2.0. Refer to the accompanying Microsoft Word document for complete
  12. //    details about MIDI Manager objects.
  13. //
  14. //    If you have comments or questions about this code, you can reach me on
  15. //    CompuServe at 70441,3055.
  16. //
  17. //--------------------------------------------------------------------------------------
  18. //---- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE ----
  19. //--------------------------------------------------------------------------------------
  20. //    If you are not familiar with programming the Apple MIDI Manager, refer to the
  21. //    "MIDI Management Tools" Version 2.0, available from APDA.  You MUST have the
  22. //    software (MIDI.H and the library) from this package in order to use these objects.
  23. //    It will not work without this.
  24. //--------------------------------------------------------------------------------------
  25. //    REVISION HISTORY:
  26. //        August ??, 1990            - Original release (1.0).
  27. //        November 5, 1990        - Added checks for midiMgrVer to most methods.
  28. //        August 1991                - updated for THINK C 5.0 as version 2.0
  29. //--------------------------------------------------------------------------------------
  30.  
  31. #include "CMIDIInputPort.h"                    // This code's header file
  32.  
  33. extern    OSType            gSignature;            // Used to register client
  34. #define noClient        '    '                // The UnClient
  35.  
  36. extern CMIDIClient * gMIDIClient;
  37.  
  38. OSErr CMIDIInputPort::IMIDIInputPort(StringPtr            theName,
  39.                                      OSType                thePortID,
  40.                                        Boolean            theVisibleFlag,
  41.                                      CMIDITimePort *    theTimePort,
  42.                                      long               theOffset,
  43.                                      short              theBufSize,
  44.                                      ProcPtr              theReadHook)
  45. {
  46.     MIDIPortParams                portParams;    // MIDI Mgr Init data structure
  47.     register MIDIPortParams *    portPPtr = &portParams;
  48.  
  49.     portPPtr->portID            = thePortID;
  50.     portPPtr->portType            = midiPortTypeInput;
  51.     if ( (theVisibleFlag == FALSE) && (itsVersion >= 0x0200) )    // Invisible input port, in 2.x
  52.         portPPtr->portType        |= midiPortInvisible;
  53.  
  54.     portPPtr->timeBase            = theTimePort ? theTimePort->GetRefNum() : 0;
  55.     portPPtr->offsetTime        = theOffset;
  56.     portPPtr->readHook            = (Ptr) theReadHook;
  57.     portPPtr->refCon            = SetCurrentA5();
  58.     BlockMove(theName, portPPtr->name, theName[0]+1);
  59.     return IMIDIPort(portPPtr, theBufSize);
  60. }
  61.  
  62. void CMIDIInputPort::Flush(void)
  63. {
  64.     if (itsVersion)
  65.         MIDIFlush(itsRefNum);
  66. }
  67.  
  68. ProcPtr CMIDIInputPort::GetReadHook(void)
  69. {
  70.     return itsVersion ? MIDIGetReadHook(itsRefNum) : 0;
  71. }
  72.  
  73. void CMIDIInputPort::SetReadHook(ProcPtr theReadHook)
  74. {
  75.     if (itsVersion)
  76.         MIDISetReadHook(itsRefNum, theReadHook);
  77. }
  78.  
  79. void CMIDIInputPort::Poll(long offsetTime)
  80. {
  81.     if (itsVersion)
  82.         MIDIPoll(itsRefNum, offsetTime);
  83. }
  84.  
  85. void CMIDIInputPort::DiscardPacket(MIDIPacketPtr thePacket)
  86. {
  87.     if (itsVersion >= 0x0200)        // Only valid on MM 2.0 or later!
  88.         MIDIDiscardPacket(itsRefNum, thePacket);
  89. }
  90.  
  91. // end of CMIDIInputPort.c
  92.